package com.ls.date;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.time.LocalDate;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = PastLocalDate.PastValidator.class)
@Documented
public @interface PastLocalDate {

	String message() default "{javax.validation.constraints.Past.message}";
	
	Class<?>[] groups() default { };
	
	Class<? extends Payload>[] payload() default { };
	
	class PastValidator implements ConstraintValidator<PastLocalDate, LocalDate> {
		public void initialize(PastLocalDate past) {
			
		}
		
		public boolean isValid(LocalDate localDate, ConstraintValidatorContext context) {
			return localDate == null || localDate.isBefore(LocalDate.now());
		}
	}
}
